//
//  MSSaleContactsOfPeopleVC.m
//  SocietySale
//
//  Created by yumingwei on 2016/12/31.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSSaleContactsOfPeopleVC.h"
#import "MSSaleContactsOfPeopleTableVC.h"
#import "MSCustomerRecommenTableVC.h"

@interface MSSaleContactsOfPeopleVC ()
@property (nonatomic, strong) MSCustomerRecommenTableVC *tableVC;

@end

@implementation MSSaleContactsOfPeopleVC

- (void)initNavigationBar{
    [super initNavigationBar];
    leftBarBtn.hidden = NO;
    titleLable.text = @"出售该联系人的人员";
}

- (void)initUI{
    self.tableVC = [[MSCustomerRecommenTableVC alloc] initWithStyle:UITableViewStyleGrouped];
    self.tableVC.view.frame = self.contentView.bounds;
    self.tableVC.enableRefresh = YES;
    self.tableVC.enableRequest = YES;
    self.tableVC.delegate = (id)self;
    self.tableVC.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.contentView addSubview:self.tableVC.view];
}

- (void)testDataFunc{
//    MSCommonModel *model = [[MSCommonModel alloc] init];
//    model.title = @"分享至朋友圈，获得5江湖币";
//    model.subTitle = @"2016.9.15";
//    model.thirdTitle = @"5";
//    
//    self.tableVC.dataArray = [@[model,model,model,model] mutableCopy];
    
    self.tableVC.pageNum = 1;
    [self request:NO];
}

- (void)updateViewController:(NSNotification *)note {
    NSDictionary *responseDic = note.userInfo;
    if (responseDic[Receiver]==self.VctrID) {
        if (responseDic[@"SaleContactsOfPeople"]!=nil){
            if (responseDic[@"state"]!=nil){
                self.tableVC.totalPagesNum = [responseDic[@"totalPage"] intValue];
                if (self.tableVC.pageNum == 1) {
                    self.tableVC.dataArray = nil;
                }
                NSMutableArray *dataArrray = [[NSMutableArray alloc] initWithArray:self.tableVC.dataArray];
                [dataArrray addObjectsFromArray:responseDic[@"SaleContactsOfPeople"]];
                self.tableVC.dataArray = dataArrray;
            }
            else{
                self.tableVC.dataArray = self.tableVC.dataArray;
            }
        }
    }
}
#pragma mark DYTableViewProtocol
/** 上拉 */
- (void)pullTableView:(UITableView *)tableView isNextPage:(BOOL)isNextPage{
    self.tableVC.pageNum++;
    [self request:YES];
}

- (void)pullRefreshRequest
{
    self.tableVC.pageNum = 1;
    [self request:YES];
}

-(void)request:(BOOL)isPull
{
    UIView * hudView = isPull?nil:self.contentView;
    NSString *pageNumber = [NSString stringWithFormat:@"%d",self.tableVC.pageNum];
    NSDictionary *dict = @{
                           @"pageNo":pageNumber,
                           @"pageSize":@"10",
                           };
    if ([_peopleId rangeOfString:@"-"].location != NSNotFound) {
        _peopleId = @"";
    }
    [netEngine requestSaleContactsOfPeopleWithTarget:self.VctrID hudView:hudView contactsId:_peopleId params:dict];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}


@end
